Answer:
No, not easily. Word processors such as Word create
files that compilers cannot use.
(Actually, they can be forced to do this,
but it is not worth the effort.)
Copying and Pasting
Here is an example Java program.
Just for fun, the program is
different than the previous examples.
The details won't be explained until later chapters.
class HelloPlanets
{
public static void main ( String[] args )
{
String[] planets = {"Mercury", "Venus", "Earth", "Mars", "Jupiter",
"Saturn", "Uranus", "Neptune", "Pluto"};
for ( int j=0; j< planets.length; j++ )
{
System.out.println("Hello " + planets[j] +"!" );
}
}
}
Here is an outline of how to run the program.
You can try this now,
or continue reading this chapter
(which shows the method step-by-step.)
Most Windows Operating Systems
- Start Notepad and a command prompt window.
- In the command window, use the CD command to go to a convenient subdirectory.
- In this example, C:\Temp will be used.
- COPY: Copy the program into the clipboard.
- In the browser window (this window), put the mouse pointer on the "c" of "class".
- Push down on the left mouse button,
then drag down until the final "}"
of the program is covered.
- Lift up on the mouse button.
- Click on the "Edit" menu of the browser and then click on "Copy".
This makes a copy of the program in the clipboard,
a section of the computer's main memory.
- PASTE: Click inside the Notepad window to make it active.
Go to its "Edit" menu and click on "paste."
You should now have have a copy of the program in Notepad.
- SAVE: Click on the "File" menu of Notepad
and "Save As"
HelloPlanets.java
.
- You will have to "navigate" to the same subdirectory as in step 2.
- RUN: Run the program:
- Click in the DOS window
Do a DIR to check that
HelloPlanets.java
is there.
- Compile the program:
C:\Temp> javac HelloPlanets.java
- Run the program:
C:\Temp> java HelloPlanets